﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FbKPI.Model;
using FbKPI.Facade;
using System.Web.Script.Serialization;
using System.Collections.ObjectModel;
using System.Web.Script.Services;

namespace FBKPI.Serializer
{
    /// <summary>
    /// Summary description for DashboardRealizationSerializer
    /// </summary>
    public class DashboardRealizationSerializer : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            string result = this.GetAllData();
            context.Response.Write(result);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private string GetAllData()
        {
            Employee User = new EmployeeFacade().GetEmployeeByID(Convert.ToInt16(HttpContext.Current.Request.Params["User"]));
            int year = DateTime.Now.Year;
            int KPIAssignID = Convert.ToInt16(HttpContext.Current.Request.Params["KPIAssign"]);

            IList<DashboardRealization> result = new List<DashboardRealization>();
            DashboardFacade pf = new DashboardFacade();
            result = pf.GetDashboardRealization(KPIAssignID, year, User);

            var gridData = new
            {
                result
            };
            var JSONSerializer = new JavaScriptSerializer();
            return JSONSerializer.Serialize(gridData);
        }
    }
}